package com.maple.exclusivesport;

import android.content.Context;
import android.content.SharedPreferences;

import com.google.gson.Gson;


public class PreferenceUtils {

    private static final String FILE_NAME = "wcr_preference";
    private static final String CONTACT_CONFIG = "contact_config";

    private static SharedPreferences getPreference(Context context) {
        return context.getApplicationContext().getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
    }


    /**
     * 保存配置信息
     *
     * @param context
     * @param info
     */
    public static void saveContactInfoBean(Context context, ContactInfoBean info) {
        getPreference(context).edit().putString(CONTACT_CONFIG, new Gson().toJson(info)).commit();
    }

    /**
     * 获取配置信息
     *
     * @param context
     * @return
     */
    public static ContactInfoBean getContactInfoBean(Context context) {
        String json = getPreference(context).getString(CONTACT_CONFIG, "");
        try {
            ContactInfoBean info = new Gson().fromJson(json, ContactInfoBean.class);
            if(info==null){
                info=new ContactInfoBean();
            }
            return info;
        } catch (Exception e) {

        }
        return new ContactInfoBean();
    }

}
